<template>
  <div>
    <load-more tip="加载数据中..." v-if="isLoading"></load-more>
    <div class="null" v-if="!isLoading && !itemData.length">
      您还有没有扣分，继续保持
    </div>
    <div style="margin-top: 0.2rem; margin-bottom: 0.2rem;" v-if="!isLoading && itemData.length">
      <group>
        <cell style="height: 1.2rem" :title="item.time" :inline-desc='item.content' v-for="(item, index) in itemData" :key="index">
          <p class="text-orange" v-if="item.type == 2">-{{item.credits}}分</p>
          <p class="text-green" v-if="item.type == 1">+{{item.credits}}分</p>
        </cell>
      </group>
    </div>
  </div>
</template>
<script>
  import PubHeader from '../../components/PubHeader.vue'
  import { get_time_format } from '../../libs/until'
  import { Cell, LoadMore } from 'vux'
  export default{
    components: {
      PubHeader,
      Cell,
      LoadMore
    },
    created() {
      this.$http.post($config.host + '/api/credit/creditsList', qs.stringify({
        uid: this.$store.state.userInfo.uid,
        client: $config.client_type,
        device: $config.device_type,
        token: this.$store.state.userInfo.token
      })).then(res => {
        const {code, data, msg} = res.data
        this.isLoading = false
        if(code == 1 && data.data_list.length) {
          data.data_list.map(item => {
            item.time = get_time_format(item.time)
            this.itemData.push(item)
          })
        } else if (code == '3') {
          this.$vux.toast.text($config.loginErrMsg, 'middle')
          this.$router.push({path: '/logout'})
        }
      }).catch(err => {
        this.$vux.toast.text($config.errMsg, 'middle')
      })
    },
    data() {
      return {
        isLoading: true,
        itemData: []
      }
    }
  }
</script>
